<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/8
 * Time: 10:03
 */

namespace app\controllers;

use yii;
use app\service\LoginService;

class UserController extends ApiBaseController
{
    public function actionInfo()
    {
        return \json_encode($this->user);
    }

    public function actionUpdate()
    {
        if (!yii::$app->request->isPost) {
            return \json_encode(['code' => 0, 'msg' => '请求方法不对']);
        }
        $password = yii::$app->request->post('password');
        $loginService = new LoginService();
        $re = $loginService->updateUser($this->user['id'], $password);
        if ($re) {
            return  json_encode(['code' => 1, 'msg' => '更新成功']);
        } else {
            return json_encode(['code' => 0, 'msg' => '更新失败，请重试']);
        }

    }
}